//
//  HDWebVC.m
//  HDWuDaDaoServiceCenter
//
//  Created by HDNiuKuiming on 2017/4/8.
//  Copyright © 2017年 HDNiuKuiming. All rights reserved.
//

#import "HDWebVC.h"

@interface HDWebVC ()
@property (weak, nonatomic) IBOutlet UIWebView *myWebview;
@property (weak, nonatomic) IBOutlet UIButton *scanBtn;

@end

@implementation HDWebVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [_myWebview setScalesPageToFit:YES];
    

    if ([_webPath.uppercaseString hasPrefix:@"HTTP"]) {
        [self loadWeb:_webPath];
    }
    else if (_newsID.length > 0) {
        [self detailNewsRequest];
    }
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    _scanBtn.hidden = YES;

    if ([_nameLabel.text containsString:@"门票"]) {
        _scanBtn.hidden = NO;
        _webVCType = kWeb_VC_Type_Ticket;
    }
}

- (void)detailNewsRequest {
    HDRequestObj *loginObj = [[HDRequestObj alloc] init];
    NSString *urlPath = [NSString stringWithFormat:@"%@g=mapi&m=Contentinfo&a=news_detail", HTTP_Request_URL_Prefix];
    NSDictionary *parameters = @{@"news_id": _newsID};
    
    [loginObj requestGetPath:urlPath Parameter:parameters withVC:self timeout:5];
    loginObj.myDataBlock = ^(NSDictionary *dataDic){
        
        NSString *loginCode = dataDic[@"status"];
        if (loginCode.integerValue == 1) {
            NSDictionary *newsDic = dataDic[@"data"];
            NSString *title = newsDic[@"title"];
            _nameLabel.text = title;
            
            NSString *htmlPath = newsDic[@"html_path"];
            if (htmlPath == nil)
                htmlPath = @"";
            
            [self loadWeb:htmlPath];
        }
        else {
        }
    };
}

- (void)loadWeb:(NSString *)path {
    
    
    NSURL *myURL = [NSURL URLWithString:path];
    NSURLRequest *request = [NSURLRequest requestWithURL:myURL];
    [_myWebview loadRequest:request];
    [_myWebview scalesPageToFit];
}

//- (void)webViewDidFinishLoad:(UIWebView *)webView
//{
//    UIFont *font = [UIFont fontWithName:@"FangSong" size:15.0f];
//    NSString *newHtmlString = [NSString stringWithFormat:@"<font face='%@' >%@", font.fontName,htmlString];
//    [self.myWebview loadHTMLString:newHtmlString baseURL:[NSURL URLWithString:self.webPath]];
//    _myWebview.delegate = nil;
//}

- (IBAction)backAction:(id)sender {
    [super back];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
